﻿using AjaxPro;
using Oracle.DataAccess.Client;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using System.Web.UI;
using WorkFlow.DBProxy;
using WorkFlow.Engine;
using WorkFlow.Engine.NSParser;

namespace WorkFlow.Desinger
{
    [AjaxNamespace("ns")]
    public partial class WFDesinger : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Utility.RegisterTypeForAjax(GetType(), Page);
            Session["USERID"] = 1;
        }

        [AjaxMethod]
        public DataTable GetUsers()
        {
            return DB.MapToDataTable(string.Format(@"select f_id as ID,f_name as NAME from t_users order by f_name"));
        }

        [AjaxMethod]
        public DataTable GetModules()
        {
            return
                DB.MapToDataTable(@"select f_id as MID,F_NAME AS MNAME ,f_url as FILES from t_modules ORDER BY F_NAME");
        }

        private string GetUID()
        {
            return Session["USERID"].ToString();
        }

        [AjaxMethod]
        public bool PraserProcess(string[] arrs, string htmls)
        {
            return new DesingerDataProcess().PraserProcess(arrs, htmls, int.Parse(GetUID()));
        }

        //获取指定流程配置信息
        [AjaxMethod]
        public string GetProcessInfo()
        {
            var obj = new[]
            {
                new OracleParameter("var_procID", OracleDbType.Int32)
            };
            obj[0].Direction = ParameterDirection.Output;
            DB.ExecuteProc("getLatestProID", obj);
            int proid = Convert.ToInt32(obj[0].Value.ToString());
            if (proid < 0) return "";

            DataTable dt =
                DB.MapToDataTable(
                    string.Format(@"select f_desinger_content as  HTMLS from tr_processes where f_id = {0}", proid));
            if (dt == null || dt.Rows.Count < 1) return "";
            return dt.Rows[0][0].ToString();
        }
    }
}